package org.ellwood.framework.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.ellwood.framework.common.core.enums.HttpCodeEnum;
import org.ellwood.framework.common.result.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @BelongsProject: ellwood-pro
 * @BelongsPackage: org.ellwood.framework.common.exception
 * @BelongsClass: GlobalExceptionHandler
 * @Description: // 异常处理
 * @Author: ellwood
 * @CreateTime: 2024/1/30 - 16:24
 * @Version: V1.0.0
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public ResponseResult<String> systemExceptionHandler(SystemException e){
        log.error("出现了异常: {}", e.getMessage(), e);
        return ResponseResult.errorResult(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult<String> exceptionHandler(Exception ex){
        log.error("出现了异常: {}", ex.getMessage(), ex);
        return ResponseResult.errorResult(HttpCodeEnum.SYSTEM_ERROR.getCode(),ex.getMessage());
    }

}
